package com.stu.config.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class ConnectionPool {
	private static final String URL="jdbc:mysql://localhost:3306/cloud?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false";
	private static final String DRIVER="com.mysql.cj.jdbc.Driver";
	private static final String USER="root";
	private static final String PASSWORD="root";

	public static Connection getConnection() {
		try {
			Class.forName(DRIVER);
			Connection connection=DriverManager.getConnection(URL, USER, PASSWORD);
			return connection;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static void closeRS(ResultSet rs) {
		try {
			if(null!=rs)
				rs.close();
		} catch (SQLException e) {
			try {
				rs.close();
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
		} 
	}
	public static void closeStat(Statement stat) {
		try {
			if(null!=stat)
				stat.close();
		} catch (SQLException e) {
			try {
				stat.close();
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
		} 
	}
	public static void closeConn(Connection conn) {
		try {
			if(null!=conn)
				conn.close();
		} catch (SQLException e) {
			try {
				conn.close();
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
		} 
	}
}
